package PersistanceLayer;

import BusinessLayer.Annee;

import PersistanceLayer.DAO;

import java.beans.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

import BusinessLayer.UE;
import PersistanceLayer.DAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import java.util.ArrayList;

import jdbc.ConnectionToOracle;

public class AnneeDAO extends DAO<Annee> {
    
    private static AnneeDAO instance;

     /* Methode permettant de recuperer l'objet unique de type AnneeDAO
     */
    public final static AnneeDAO getInstance() {
    	if(instance == null)
    	{
    		instance = new AnneeDAO();
    	}
        return instance;
    }


    @Override
    public boolean create(Annee obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean update(Annee obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean update(Annee ancien, Annee nouveau) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Annee find(Annee obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean delete(Annee obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<Annee> getListe() {
    	String versionEtape;
    	    	
    	ArrayList<Annee> ensAnnee = new ArrayList<Annee>();

    	
    	try {
    		
    		java.sql.Statement state =this.connect.createStatement();
    		
			ResultSet res = this.connect.createStatement()
			.executeQuery("SELECT * FROM annee");
		

			while(res.next()){	
				if(res.getObject(1) != null)
					versionEtape = res.getObject(1).toString();
				else
					versionEtape = "";
				
				
				ensAnnee.add(new Annee(versionEtape));				
				
				
			}
			
			state.close();
			res.close();
			
			return ensAnnee;
    	} catch (SQLException e) {
			// 
    		
			e.printStackTrace();
			return null;
		}
    	
    }
    

    /**
     * name repr�sente le nom du d�partement contenant l'ensemble d'ann�es
     * que l'on veut r�cup�rer
     */
	@Override
	public ArrayList<Annee> getListe(String name) {
		// TODO Auto-generated method stub
		ArrayList<Annee> resAnnees = new ArrayList<Annee>();
		try {
	
			//Cr�ation d'un objet Statement
			java.sql.Statement state = this.connect.createStatement();
			//L'objet ResultSet contient le r�sultat de la requ�te SQL
			ResultSet result = state.executeQuery("SELECT A.VERSIONETAPE " +
					"FROM ANNEE A,DEPARTEMENT D " +
					"WHERE D.NOMDEPARTEMENT = '"+name+"' " +
					"AND D.IDDEPARTEMENT = A.IDDEPARTEMENT");
			
			

			while(result.next()){		
				
				resAnnees.add(new Annee(result.getObject(1).toString()));

			}


             result.close();
             state.close();

			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return resAnnees;
	}


	@Override
	public String getNom(String name) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public boolean update(String a, String b, String c, String d) {
		// TODO Auto-generated method stub
		return false;
	}


    	

}